package main

import (
	"fmt"
	"go_code/test/ginchat/models"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"time"
)

func main() {
	db, err := gorm.Open(mysql.Open("root:123456@tcp(192.168.8.151:3306)/ginchat?charset=utf8mb4&parseTime=True&loc=Local"), &gorm.Config{})
	if err != nil {
		panic("failed to connect database")
	}
	db.AutoMigrate(&models.UserBasic{})
	user := &models.UserBasic{}
	user.Name = "admin"
	user.Password = "admin"
	user.PhoneNumber = "12345678901"
	user.Identity = "12345678901"
	user.Email = "admin@admin.com"
	user.ClientIp = "127.0.0.1"
	user.ClientPort = "8080"
	user.DeviceInfo = "pc"
	user.IsLogOut = false
	user.LoginTime = uint64(time.Now().UnixMilli())
	user.HeartbeatTime = uint64(time.Now().UnixMilli())
	user.LogOutTime = uint64(time.Now().UnixMilli())

	db.Create(user)

	fmt.Printf("%#v\n", db.First(user, 1))

	db.Model(user).Update("name", "admin1")
	fmt.Printf("%#v\n", db.First(user, 1))

}
